<?php  
class BackupController extends AuthController{
	
	public function __init(){}

	public function backup(){//备份数据库
		$result = Backup::backup(//
            array(
                "size" => 200,//每个卷多大,单位是KB
                "dir" => C("DB_BACKUP").date("Ymdhis")//备份文件存放目录，不填则使用 C('DB_BACKUP')
            )
        );
        if ($result['status'] == 'success') {
        	$this->success($result['message'], U('index'));
        } else {
            $this->success($result['message'], $result['url'], 0.2);//0.2为每次间隔时间,php脚本时间为30秒超出则超时
        }
	}
	//备份文件列表
	public function index(){
		$dirs=Dir::tree('Backup');
		// p($dirs);exit;
		$this->assign('dirs',$dirs);
		$this->display();
	}
	//还原数据库
	public function recovery(){
		 $dir = C("DB_BACKUP") . Q("dir");//备份数据存放的目录
		$result = Backup::recovery(array('dir' => $dir));
		if ($result['status'] == 'success') {
			$this->success($result['message'], U('index'));
		}else{
			$this->success($result['message'], $result['url'], 0.2);
		}
	}
	//删除数据备份文件
	public function del(){
		$dir=Q('dir');
		if(Dir::del(C('DB_BACKUP').$dir)){
			$this->success('删除成功');
		}else{
			$this->error('删除失败');
		}
	}
}
?>